How To Get the Current Logged in User

Description

The context.security object can be used to get the id for the currently logged in user.

Discussion

If the security system has been enabled in an application, you can get the id for the currently logged in user using context.security.currentUser. If the user is logged in, context.security.currentUser will contain the user's id. If the user is not logged in, context.security.currentUser will be blank.

Before using the value in context.security.currentUser, you must first verify that no error occurred when fetching the user id. If an error occurred, the value in context.security.currentUser cannot be used.

The context.security.callResult object can be checked to verify the operation was successful. You should always check the value of context.security.callResult before using the value from any property or method of the context.security object.

The example below demonstrates how to get the user id:

dim userName as C = Context.Security.CurrentUser

if .not. Context.Security.CallResult.Success then 
   error_generate(Context.Security.CallResult.Text) 
end if 

if alltrim(userName) = "" then 
   'Display  "no user is logged in." 
else 
   'Display user name 
end if

See Also